package com.pet.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pet.service.SysPetHealthStatusService;
import com.pet.system.SysPetHealthStatus;
import com.pet.utils.Result;
import com.pet.vo.SysPetHealthStatusQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 宠物健康状态表 前端控制器
 * </p>
 *
 * @author whd
 * @since 2023-08-01
 */
@Api(tags = "宠物健康状态表前端控制器")
@RestController

@RequestMapping("/lovePet/system/sysPetHealthStatus")
@CrossOrigin("*")
public class SysPetHealthStatusController {

    @Autowired
    private SysPetHealthStatusService sysPetHealthStatusService;


    /**
     *
     * 分页和条件查询
     *
     * @param page
     * @param limit
     * @param sysPetHealthStatusQueryVo
     * @return
     */
    @ApiOperation("分页和查询宠物健康状态")
    @PostMapping("/{page}/{limit}")
    public Result findCategoryByPageQuery(@ApiParam("页码") @PathVariable Long page,
                                          @ApiParam("每页条数") @PathVariable Long limit,
                                          @ApiParam("包装的查询分类名称") @RequestBody SysPetHealthStatusQueryVo sysPetHealthStatusQueryVo) {

        System.out.println("========>" + sysPetHealthStatusQueryVo.getName());

        //1.创建分页对象
        IPage<SysPetHealthStatus> iPage = new Page<>(page, limit);
        //2.调用方法
        iPage = this.sysPetHealthStatusService.selectPage(iPage, sysPetHealthStatusQueryVo);
        //3.返回
        return iPage == null ? Result.fail() : Result.ok(iPage);
    }

    /**
     *
     * 获取所有宠物健康状态
     *
     * @return
     */
    @ApiOperation("获取所有宠物健康状态")
    @GetMapping("/findAll")
    public Result findAllPetHealthStatus() {
        List<SysPetHealthStatus> list = sysPetHealthStatusService.list();
        return Result.ok(list);
    }



    /**
     *
     * 批量删除宠物健康状态
     *
     * @param ids
     * @return
     */
    @ApiOperation("批量删除宠物健康状态")
    @DeleteMapping("/removePetHealthStatusByIds")
    public Result removePetHealthStatusByIds(@ApiParam("待删除的宠物健康状态ID列表") @RequestBody List<Long> ids) {
        boolean b = this.sysPetHealthStatusService.removeBatchByIds(ids);
        return b ? Result.ok() : Result.fail();
    }



    /**
     *
     * 添加宠物健康状态
     *
     * @param sysPetHealthStatus
     * @return
     */
    @ApiOperation("添加宠物健康状态")
    @PostMapping("/addPetHealthStatus")
    public Result addPetHealthStatus(@ApiParam("宠物健康状态信息") @RequestBody SysPetHealthStatus sysPetHealthStatus) {
        boolean b = this.sysPetHealthStatusService.save(sysPetHealthStatus);
        return b ? Result.ok() : Result.fail();
    }

    /**
     * 1.根据id 去得到当前分类
     *
     * @param id
     * @return
     */
    @ApiOperation("根据ID获取宠物健康状态")
    @GetMapping("/findPetHealthStatusById/{id}")
    public Result findPetHealthStatusById(@ApiParam("宠物健康状态ID") @PathVariable Long id) {
        SysPetHealthStatus sysPetHealthStatus = this.sysPetHealthStatusService.getById(id);
        return Result.ok(sysPetHealthStatus);
    }


    /**
     * 更新宠物健康状态
     *
     * @param sysPetHealthStatus
     * @return
     */
    @ApiOperation("更新宠物健康状态")
    @PostMapping("/updatePetHealthStatusById")
    public Result updatePetHealthStatusById(@ApiParam("宠物健康状态信息") @RequestBody SysPetHealthStatus sysPetHealthStatus) {
        boolean b = this.sysPetHealthStatusService.updateById(sysPetHealthStatus);
        return b ? Result.ok() : Result.fail();
    }



    /**
     * 根据ID删除宠物健康状态
     *
     * @param id
     * @return
     */
    @ApiOperation("根据ID删除宠物健康状态")
    @DeleteMapping("/removePetHealthStatusById/{id}")
    public Result removePetHealthStatusById(@ApiParam("宠物健康状态ID") @PathVariable Long id) {
        boolean b = this.sysPetHealthStatusService.removeById(id);
        return b ? Result.ok() : Result.fail();

    }


}

